package com.mydemo.common.utils;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * Servlet工具类
 * @author Last_Island
 * @version 1.0
 */
public class ServletUtils {

    /**
     * 获取RequestAttributes
     * @return
     */
    public static RequestAttributes getAttribute(){
        return RequestContextHolder.getRequestAttributes();
    }

    /**
     * 获取ServletRequestAttributes
     * @return
     */
    public static ServletRequestAttributes getRequestAttributes(){
        return (ServletRequestAttributes) getAttribute();
    }

    /**
     * 获取request
     * @return
     */
    public static HttpServletRequest getHttpServletRequest(){
        return getRequestAttributes().getRequest();
    }

    /**
     * 获取response
     * @return
     */
    public static HttpServletResponse getHttpServletResponse(){
        return getRequestAttributes().getResponse();
    }
}
